var orderManage = function() {

	var _init = function() {

		var table = $('#table_order');
        var  uperUserId=$('#uperUserId').val();
		var tableUnit=table.dataTable({
			"processing": true,
			"serverSide": true,
			"ajax": {
				url:"/a/wxconf/comm/profit",
				data:{"type":'2',"uperUserId":uperUserId}  //收益
			},
			"autoWidth": false,
			"columns": [
				{
					"width": "12%",//买家
					"data": "nickName",
					"render": function(data, type, row, meta) {
						if(data=='--'){
							return "未绑定微信昵称";
						}else{
							return data;
						}
				      }
				},{
					"width": "8%",//订单号
					"data":"orderNO"
				
				},{
					"width": "10%",//成交数量
					"data": "orderId",
					"render": function(data, type, row, meta) {
						var val=0;
						if(data!=null&&data!=''){
							$.ajax({
								url : '/a/user/order/product',
								type : 'post',
								dataType : 'json',
								contentType:"application/json; charset=utf-8",
								async: false,
								data : JSON.stringify({ id: data }),
							}).done(function(r) {
								if (r.status === '1') { 
									if(r.data.length>=1){
										for(var i=0;i<r.data.length;i++){
											val+=r.data[i].count;
										}
									}else{
										val=0;//r.data.属性
									}
								} else if (r.status == '2') {

								}
							});
							return val;
						}else
							return "--";

					}
				},
				{
					"width": "9%",//订单金额
					"data":"total",
					"render":function(data, type, row, meta) {
						if(data){
							return data/100;
						}else{
							return "--";
						}
					}
				},
				{
					"width": "9%",
					"data": "amount" ,
					"render": function(data, type, row, meta) {
						if(data){
							return data/100
						}else{
							return "--"
						}
					   
				      }
				}
				,
				{
					"width": "7%",
					"data":"creatDate",//交易时间,
					"render":function(data, type, row, meta) {
						if(data){
							return moment(data).format('YYYY-MM-DD HH:mm');
						}else{
							return "--";
						}
						
					}
				},{
                    "width": "8%",//订单号
                    "data":"orderId",
					"render":function(data,type,row,meta){
                        var val ="正常";
                        if(data!=null&&data!=''){
                            $.ajax({
                                url : '/a/user/order/getOrder?id='+encodeURIComponent(data),
                                // type : 'post',
                                dataType : 'json',
                                contentType:"application/json; charset=utf-8",
                                async: false,
                               // data : JSON.stringify({ id: data }),
                            }).done(function(r) {
                                if (r.status === '1') {
                                    if(r.data){
                                    	if(r.data.status==0||r.data.status==6){
                                    		val="售后";
										}
									}
                                }
                            });
                            return val;
                        }else
                            return val;
					}

                },
				
				],
				"language": {
					url: '/assets/pages/Chinese.json'
				},
				"pageLength": 10,
				/*"order":false,*/
				"order": [
					[5, "desc"]
					],
					"columnDefs": [{
						"orderable": false,
						"targets": [2]
					}],
            "dom": "<'row'<'.col-md-6 col-sm-12'><'col-md-6 col-sm-12'>r>" +
            "<t>" +
            "<'row'<'col-md-5'i><'col-md-7'>p>",
            "fnInitComplete": function() {},
            "fnDrawCallback": function(){
            }
		});
	}

	return {
		init: function() {
			_init();
		}

	};

}();

$(function() {

	orderManage.init();
});